/*
    设计思想：
    通过 useReducer 和 createContext 来创建状态管理工具
    1，通过 createContext 创建全局上下文对象
    2，通过 useReducer 创建状态管理方法
*/
import React, { useState, createContext, useReducer } from 'react';
import { IProviderProps } from '@/types/common';
import { IStoreState } from '@/types/store';
import { reducer } from './reducer';
import { Context } from './context';

const Provider: React.FC<IProviderProps> = ({children}) => {
    const initState: IStoreState = {
        consName: '白羊座',
        filed: 'today',
        today: {},
        tomorrow: {},
        week: {},
        month: {},
        year: {}
    };
    const [state, dispatch] = useReducer(reducer, initState);
    
    return (
        <>
            <Context.Provider value={{state, dispatch}}>
                {children}
            </Context.Provider>
        </>
    );
};

export default Provider;